package com.sds.sweng.swat.miplatform.ui.design.figures.geps;

import org.apache.commons.lang.StringUtils;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Color;

import com.sds.sweng.swat.miplatform.ui.design.utils.FontUtils;

public class GepsTitleSubAreaFigure extends Label {

	private static final Color titleColor = new Color(null, 16, 132, 170);

	private String title = StringUtils.EMPTY;

	public GepsTitleSubAreaFigure() {
		this(StringUtils.EMPTY);
	}

	public GepsTitleSubAreaFigure(String text) {
		super(text);

		setBorder(new LineBorder(ColorConstants.black));
		setFont(FontUtils.DEFAULT_FONT);
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	protected void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);

		if (!StringUtils.isEmpty(getTitle())) {
			setFont(FontUtils.TITLE_FONT);
			setForegroundColor(titleColor);

			int x = bounds.x+1;
			int y = bounds.y;

			graphics.drawImage(ImageDescriptor.createFromFile(getClass(), "images/icon_title.gif").createImage(), x, y+7);
			graphics.drawText(getTitle(), x+15, y+7);
		} else {
			setFont(FontUtils.DEFAULT_FONT);
			setForegroundColor(ColorConstants.black);
		}
	}

}
